package com.fz.us.oa.core.dao.com.impl;

import com.fz.us.admin.base.dao.impl.BaseDaoImpl;
import com.fz.us.admin.company.entity.User;
import com.fz.us.oa.core.dao.com.FriendDao;
import com.fz.us.oa.core.entity.com.Friend;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by ZhuChunXiao on 2017/7/6.
 */
@Repository
public class FriendDaoImpl extends BaseDaoImpl<Friend, String> implements FriendDao {
    @Override
    public List<Friend> getFriendList(User own) {
        List<Friend> friendList=getSession().createQuery("from Friend f where f.own=?").setParameter(0, own).list();
        return friendList;
    }

    @Override
    public Friend getFriend(User own, User friend) {
        List<Friend> friendList=getSession().createQuery("from Friend f where f.own=? and f.friend=?").setParameter(0,own).setParameter(1,friend).list();
        if(friendList.size()>0){
            return friendList.get(0);
        }else{
            return null;
        }
    }
}
